/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.display;

import plash.events.Event;
import plash.events.EventDispatcher;
import plash.geom.Point;
import plash.geom.Rectangle;
import plash.utils.Math;
import processing.core.PApplet;

/**
 *
 * @author User
 */
abstract class DisplayObject extends EventDispatcher implements IDrawable
{
    protected String __name="";
    protected int __x = 0;
    protected int __y = 0;
    protected int __rotation=0;
    protected int __width=0;
    protected int __height=0;
    protected float __alpha=1.0f;
    protected int __mouseX=0;
    protected int __mouseY=0;
    protected float __radiansRotation=0;
    protected float __scaleX = 1.0f;
    protected float __scaleY = 1.0f;
    
    protected boolean __visible = true;
    
    protected Point __location = new Point();
    protected Rectangle __boundingBox = new Rectangle();
    
    protected DisplayObject __mask;
    protected DisplayObjectContainer __parent;
    protected PApplet __painter;

    public DisplayObject()
    {
    }

    @Override
    public void draw()
    {
        if (__painter == null)
        {
            return;
        }
        dispatchEvent(new Event(Event.ENTER_FRAME));
    }

    public String getName()
    {
        return __name;
    }

    public void setName(String name)
    {
        this.__name = name;
    }

    public int getX()
    {
        return __x;
    }

    public void setX(int x)
    {
        __location.setX(x);
        this.__x = x;
    }

    public int getY()
    {
        return __y;
    }

    public void setY(int y)
    {
        __location.setY(y);
        this.__y = y;
    }

    public int getRotation()
    {
        return __rotation;
    }

    public void setRotation(int rotation)
    {
        this.__rotation = rotation;
        this.__radiansRotation = Math.toRadians(rotation);
    }

    public int getWidth()
    {
        return __width;
//        return (int) (__boundingBox.getWidth() * this.__scaleX);
    }

    public void setWidth(int width)
    {
        this.__width = width;
    }

    public int getHeight()
    {
        return __height;
//        return (int) (__boundingBox.getHeight() * this.__scaleY);
    }

    public void setHeight(int height)
    {
        this.__height = height;
    }

    public float getAlpha()
    {
        if(this.__parent != null)
        {
            return this.__alpha * this.__parent.getAlpha();
        }
        return __alpha;
    }

    public void setAlpha(float alpha)
    {
        this.__alpha = alpha;
    }

    public int getMouseX()
    {
        return __mouseX;
    }

    public void setMouseX(int mouseX)
    {
        this.__mouseX = mouseX;
    }

    public int getMouseY()
    {
        return __mouseY;
    }

    public void setMouseY(int mouseY)
    {
        this.__mouseY = mouseY;
    }

    public boolean isVisible()
    {
        return __visible;
    }

    public void setVisible(boolean visible)
    {
        this.__visible = visible;
    }

    public DisplayObjectContainer getParent()
    {
        return __parent;
    }

    public void setParent(DisplayObjectContainer parent)
    {
        this.__parent = parent;
    }

    public PApplet getPainter()
    {
        return __painter;
    }

    public void setPainter(PApplet painter)
    {
        this.__painter = painter;
    }

    public float getScaleX()
    {
        return __scaleX;
    }

    public void setScaleX(float scaleX)
    {
        this.__scaleX = scaleX;
    }

    public float getScaleY()
    {
        return __scaleY;
    }

    public void setScaleY(float scaleY)
    {
        this.__scaleY = scaleY;
    }

    public Rectangle getBoundingBox()
    {
        return __boundingBox;
    }
    
    public void setLocation(Point p)
    {
        this.setX(p.getX());
        this.setY(p.getY());
    }
    
    public void setLocation(int x, int y)
    {
        this.setX(x);
        this.setY(y);
    }

    public Point getLocation()
    {
        __location.setX(__x);
        __location.setY(__y);
        return __location;
    }
    
}
